package database

import (
	"crypto/sha256"
	"encoding/hex"
	"encoding/json"
	"time"
)

type EVENT struct {
	E_id     int    `json:"id"`
	E_name   string `json:"name"`
	E_start  int64  `json:"start_time"`
	E_end    int64  `json:"end_time"`
	hashcode string
}

//按照 `["e_name",start_year,start_month,start_day,end_year,end_month,end_day]` 进行格式化
func (e *EVENT) FORMAT_WIKI() (event []interface{}) {
	start := time.Unix(e.E_start, 0)
	end := time.Unix(e.E_end, 0)

	event = append(event, e.E_name, start.Year(), start.Month(), start.Day(), end.Year(), end.Month(), end.Day())
	return
}

//返回已经已填充的哈希值
func (e *EVENT) GetHashCode() string {
	return e.hashcode
}

//计算当前对象的sha256值
func (e *EVENT) HASHCODE() (hashcode string) {
	data, _ := json.Marshal(e)
	hBytes := sha256.Sum256(data)
	hashcode = hex.EncodeToString(hBytes[:])
	return
}
